#!/usr/bin/python

"""
Execute a python module/class. Print the status.
    Usage: test_py.py <mod>.py
"""

__author__ = 'liwei79@gmail.com'

import os
import sys
import getopt

if __name__ != "__main__":
    sys.exit(0);

opts, args  = getopt.getopt(sys.argv[1:], "h", ["help"])
for o, a in opts:
    if o in ("-h", "--help"):
        print "usage:"

py_file = args[0]

dir = os.getcwd()
py_file_path = "%s/%s" % (dir, py_file)

pipe = os.popen(py_file_path, 'r');
output = pipe.readlines();
status = pipe.close();

if status:
    print "(FAILED) %s - SELF TESTING" % py_file
    print "=== FAIL LOG - %s ===" % py_file
    for line in output:
        print line,
    print "=== END FAIL LOG - %s ===" % py_file
else:
    print "(PASSED) %s - SELF TESTING" % py_file

